package com.chzc.goods.controller;

import com.chzc.goods.service.IGoodsCarService;
import com.chzc.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cv大魔王
 * @version 1.0
 * @date 2021/6/6 16:41
 */
@Api(value = "购物车接口(私有)", tags = "购物车接口(私有)")
@RestController
@RequestMapping("/pri/goods/car")
public class GoodsCarController {

    @Autowired
    private IGoodsCarService goodsCarService;

    @ApiOperation("添加购物车")
    @GetMapping("/{goodsId}/{buyNum}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true),
            @ApiImplicitParam(name = "buyNum", value = "商品数量,秒杀商品限购一件", required = true)
    })
    public Result add(@PathVariable String goodsId, @PathVariable Integer buyNum) {
        return goodsCarService.add(goodsId,buyNum);
    }

    @ApiOperation("查询该用户购物车信息")
    @GetMapping("/findAll")
    public Result findAll() {
        return goodsCarService.findAll();
    }

    @ApiOperation("在购物车删除某件商品")
    @DeleteMapping("/{goodsId}")
    @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true)
    public Result deleteByGoodsId(@PathVariable String goodsId) {
        return goodsCarService.deleteByGoodsId(goodsId);
    }


    @ApiOperation("清空用户购物车")
    @DeleteMapping
    public Result deleteByGoodsId() {
        return goodsCarService.deleteAll();
    }

}
